<?php
    session_start();

    function BacaDir($dir,$num) {
       // open the directory
       $dhandle = opendir($dir);

       if ($dhandle) {
          while (false !== ($fname = readdir($dhandle))) {
             if (is_dir( "{$dir}/{$fname}" )) {
                if (($fname != '.') && ($fname != '..')) {
                   echo "
                    <div class=dir$num><img src='image/exp.jpg' height='10px' onClick=Ambil('$dir/$fname',$num+1) alt='gambar tidak bisa ditampilkan'/><b>{$dir}/{$fname}</b>
                    <div id=$dir/$fname></div>
                   </div>";
                }
             }
             else {
                $type=filetype("$dir/$fname");
                echo "<div class=file$num><t>{$fname}</t>
                <a href=downloadfile.php?file=$dir/$fname&&type=$type>download</a>
                </div>";
             }
          }
          closedir($dhandle);
        }
    }

    BacaDir($_GET['file'], $_GET['num']);
?>
